<template>
	<view class="business">
		<view class="inputlist">
			<view class="left">
				<text class="hx">*</text>
				<text>商家账号</text>
			</view>
			<view class="right">
				<input type="text" placeholder="商家账号" v-model="shop_username" placeholder-class="inputColor" disabled>
			</view>
		</view>
		<view class="inputlist">
			<view class="left">
				<text class="hx">*</text>
				<text>打赏账号</text>
			</view>
			<view class="right">
				<input type="text" placeholder="请输入打赏账号" v-model="username" placeholder-class="inputColor">
			</view>
		</view>
		<view class="inputlist">
			<view class="left">
				<text class="hx">*</text>
				<text>赠送绿色积分</text>
			</view>
			<view class="right">
				<input type="number" placeholder="请输入打赏金额" v-model="num" placeholder-class="inputColor"
					@input="handle_data">
			</view>
		</view>
		<view class="inputlist">
			<view class="left">
				<text class="hx">*</text>
				<text>销毁额度</text>
			</view>
			<view class="right">
				<input type="text" :value="reduce_price" placeholder-class="inputColor" disabled="true">
			</view>
		</view>
		<view class="inputlist">
			<view class="left">
				<text class="hx">*</text>
				<text>打赏成本</text>
			</view>
			<view class="right">
				<input type="text" :value="'￥'+coin_rate+'/YSB'" placeholder-class="inputColor" disabled="true">
			</view>
		</view>
		<view class="inputlist">
			<view class="left">
				<text class="hx">*</text>
				<text>销毁YSB</text>
			</view>
			<view class="right">
				<input type="text" :value="reduce_coin" placeholder-class="inputColor" disabled="true">
			</view>
		</view>
		<view class="inputlist type_item">
			<view class="left">
				<text class="hx">*</text>
				<text>划转方式</text>
			</view>
			<view class="typelist">
				<radio-group name="typeCheck" @change="radioC">
					<label>
						<radio value="3" checked="true" /><text>YSB</text>
					</label>
					<!-- <label>
						<radio value="1" /><text>余额</text>
					</label> -->

				</radio-group>
			</view>
		</view>
		<PasswordBox @getpassword="getpassword" @closeBox="closeBox" :pShow="pShow"></PasswordBox>
		<view class="btn">
			<button class="btn_sumbit" @click="sumbit">确认</button>
		</view>
	</view>
</template>

<script>
	import {
		ShopReward,
		Index
	} from "@/api/user.js"
	import PasswordBox from "@/components/passwordbox/p_box.vue"
	export default {
		components: {
			PasswordBox
		},
		data() {
			return {
				businessType: [1, 2, 3],
				businessName: '请选择商家类型',
				address: '请选择地域',
				pShow: false,
				num: '',
				shop_username: '',
				username: '',
				shop_percent: 0,
				coin_rate: 1,
				reduce_price: 0, //销毁额度
				reduce_coin: 0, //销毁YSB
				type: 3 //支付方式
			}
		},
		onLoad() {
			this.Index()
		},
		methods: {
			Index() {
				Index().then(res => {
					console.log(res);
					this.shop_username = res.data.info.username
					this.shop_percent = res.data.shop_percent
					this.coin_rate = res.data.coin_rate
				})
			},
			handle_data(e) {
				console.log(e);
				let num = e.detail.value
				this.reduce_price = parseFloat(num * this.shop_percent / 100).toFixed(10)
				this.reduce_coin = parseFloat(this.reduce_price / this.coin_rate).toFixed(10)

			},
			radioC(e) {
				this.type = e.detail.value
			},
			closeBox(e) {
				this.pShow = e
			},
			sumbit() {
				this.pShow = true
			},
			getpassword(e) {
				this.pShow = false
				ShopReward({
					username: this.username,
					num: this.num,
					type: this.type,
					password: e
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: "none"
					})
					if (res.status == 1) {
						this.num = ''
						this.username = ''
					}

				})
			},
			getAddress() {
				uni.getLocation({
					success: (res) => {
						console.log(res);
					}
				})
			},
			businessChoose(e) {
				let i = e.detail.value
				this.businessName = this.businessType[i]
			},
			imgUp() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						uni.uploadFile({
							url: that.requestUrl + 'Upload/',
							method: "POST",
							filePath: res.tempFilePaths[0],
							fileType: 'image',
							name: 'image',
							header: {
								'token': uni.getStorageSync('token'),
							},
							success: (res) => {
								let info = JSON.parse(res.data)
								let url = info.data.fullurl
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #eee;
	}

	.type_item {
		display: flex;
		align-items: center;
		padding: 5px 0;
		font-size: 14px;

		text {
			margin-right: 20px;
		}

		radio-group {
			display: flex;
		}

		label {
			display: flex;
			align-items: center;
		}
	}

	.btn {
		margin-top: 40px;

		.btn_sumbit {
			background: #ff3939;
			color: #fff;
			width: 80%;
			font-size: 14px;
			box-sizing: border-box;
		}
	}

	.imgbox {
		font-size: 14px;
		padding: 10px;
		background-color: #fff;

		image {
			margin-top: 10px;
			width: 100px;
		}
	}

	.inputlist {
		background-color: #fff;
		display: flex;
		font-size: 14px;
		padding: 10px;
		border-bottom: 1px solid #eee;

		.left {
			width: 30%;
			display: flex;

			.hx {
				display: block;
				width: 5px;
				color: red;
				margin-right: 3px;
			}
		}

		.right {
			width: 70%;

			input {
				font-size: 14px;
			}

			.picker_text {
				color: #ccc;
			}

			.inputColor {
				color: #ccc;
			}


		}
	}
</style>
